<template>
  <a-card :bordered="false">

    <!-- 查询区域 -->
    <div class="table-page-search-wrapper search-box-cuesList">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">

          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="数据名称">
              <a-input placeholder="请输入"></a-input>
            </a-form-item>
          </a-col>
          <a-col :md="4" :sm="6">
            <a-form-item label="确认状态">
              <a-select placeholder="请选择">
                <a-select-option value="1">未确认</a-select-option>
                <a-select-option value="2">已确认</a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
              <a @click="handleToggleSearch" style="margin-left: 8px">
                {{ toggleSearchStatus ? '收起' : '展开' }}
                <a-icon :type="toggleSearchStatus ? 'up' : 'down'" />
              </a>
            </span>
          </a-col>

        </a-row>
      </a-form>
    </div>

    <!-- table区域-begin -->
    <div>
      <a-table ref="table" size="middle" bordered rowKey="id" :columns="columns" :dataSource="dataSource" :pagination="ipagination" :loading="loading" :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}" @change="handleTableChange">
        <span slot="action" slot-scope="text, record">
          <a @click="handleToEdit(record)">编辑</a>
          &nbsp;&nbsp;
          <a @click="exprotXls(record)">导出</a>
        </span>
      </a-table>
    </div>
    <!-- table区域-end -->
  </a-card>
</template>

<script>
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import { USER_INFO } from '@/store/mutation-types'
import { downFile } from '@/api/manage'
import Vue from 'vue'

export default {
  name: 'DepartPerformance',
  mixins: [JeecgListMixin],
  data() {
    return {
      departList: [],
      allMonthList: [],
      description: 'PerformanceMonth管理页面',

      // 表头
      columns: [
        {
          title: '编号',
          align: 'center',
          dataIndex: 'id',
        },
        {
          title: '数据名称',
          align: 'center',
          dataIndex: 'name',
        },
        {
          title: '归属部门',
          align: 'center',
          dataIndex: 'departName',
        },
        {
          title: '确认状态',
          align: 'center',
          customRender: data => {
            if (data.sureFlag == 1) {
              return '未确认'
            }
            return '已确认'
          },
        },
        {
          title: '创建时间',
          align: 'center',
          dataIndex: 'createTime',
        },
        {
          title: '操作',
          dataIndex: 'action',
          align: 'center',
          scopedSlots: { customRender: 'action' },
        },
      ],
      url: {
        list: '/performance/performanceMonthDepart/list',
        exportXlsUrl: '/performance/performanceMonthDepart/exportXls',
      },
      userInfo: null,
      disableMixinCreated: true,
    }
  },
  created() {
    this.userInfo = Vue.ls.get(USER_INFO)
    // console.log(this.userInfo)
    this.queryParam.departId = this.userInfo.departIds
    this.searchQuery()
  },
  mounted() {},
  methods: {
    handleToEdit(record) {
      console.log(record)
      this.$router.push({
        path: '/performance/DepartPerformanceEdit',
        query: { id: record.perforMonthId, departId: record.departId, departName: record.departName },
      })
    },
    exprotXls: function(record) {
      var url = this.url.exportXlsUrl
      downFile(url, { perforMonthId: record.id, name: record.name, departId: this.queryParam.departId }).then(data => {
        if (!data) {
          this.$message.warning('文件下载失败')
          return
        }
        if (typeof window.navigator.msSaveBlob !== 'undefined') {
          window.navigator.msSaveBlob(new Blob([data], { type: 'application/vnd.ms-excel' }), fileName + '.xls')
        } else {
          let url = window.URL.createObjectURL(new Blob([data], { type: 'application/vnd.ms-excel' }))
          let link = document.createElement('a')
          link.style.display = 'none'
          link.href = url
          link.setAttribute('download', record.name + '.xls')
          document.body.appendChild(link)
          link.click()
          document.body.removeChild(link) // 下载完成移除元素
          window.URL.revokeObjectURL(url) // 释放掉blob对象
        }
      })
    },
  },
}
</script>
<style scoped>
@import '~@assets/less/common.less';
</style>